//
//  startMoneyTableViewCell.m
//  ioschishan
//
//  Created by 千翼网络科技 on 2017/7/17.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "startMoneyTableViewCell.h"


@implementation startMoneyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:@"identifier"]) {
        
        [self initView];
    }
    return self;
}

#pragma mark ---------------- init -----------------

- (void)initView{

    self.backgroundColor = getColor(@"ffffff");
    
    _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, scrWidth(), scrHeight())];
    _bgView.backgroundColor = [UIColor blackColor];
    _bgView.alpha = 0.1;
    _bgView.hidden = YES;
    [[[UIApplication sharedApplication]keyWindow] addSubview:_bgView];
//    [[[UIApplication sharedApplication]keyWindow] addSubview:self.pickerView];
    
    UILabel *moneyLabel = [[UILabel alloc]init];
    moneyLabel.text = @"目标金额";
    moneyLabel.numberOfLines = 1;
    moneyLabel.textColor = getColor(@"4a4a4a");
    moneyLabel.textAlignment = NSTextAlignmentLeft;
    moneyLabel.font = get4sFont(12);
    [self addSubview:moneyLabel];
    [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        
        
    }];
    
    _moneyTextField = [[UITextField alloc]init];
    _moneyTextField.textColor = getColor(@"4a4a4a");
    _moneyTextField.placeholder = @"请填写目标金额";
    _moneyTextField.keyboardType = UIKeyboardTypeNumberPad;
    _moneyTextField.font = get4sFont(12);
    _moneyTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:_moneyTextField];
    [_moneyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(2));
        make.left.mas_equalTo(self).with.offset(screenScale(85));
        make.right.mas_equalTo(self).with.offset(screenScale(-35));
        make.height.mas_equalTo(screenScale(44));
    }];
    
    UILabel *rightLabel = [[UILabel alloc]init];
    rightLabel.text = @"元";
    rightLabel.textColor = getColor(@"4a4a4a");
    rightLabel.textAlignment = NSTextAlignmentLeft;
    rightLabel.font = get4sFont(12);
    [self addSubview:rightLabel];
    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(15));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        
        
    }];
    
    UIView *threadView = [[UIView alloc]init];
    threadView.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:threadView];
    [threadView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self).with.offset(screenScale(44));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    ///目标金额
    
    UILabel *wayLabel = [[UILabel alloc]init];
    wayLabel.text = @"资金用途";
    wayLabel.numberOfLines = 1;
    wayLabel.textColor = getColor(@"4a4a4a");
    wayLabel.textAlignment = NSTextAlignmentLeft;
    wayLabel.font = get4sFont(12);
    [self addSubview:wayLabel];
    [wayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(threadView).with.offset(screenScale(15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        
        
    }];
    
    _wayTextField = [[UITextField alloc]init];
    _wayTextField.textColor = getColor(@"4a4a4a");
    _wayTextField.placeholder = @"请填写资金用途，发布后不可编辑";
    _wayTextField.font = get4sFont(12);
    _wayTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:_wayTextField];
    [_wayTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(threadView).with.offset(screenScale(2));
        make.left.mas_equalTo(self).with.offset(screenScale(85));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        make.height.mas_equalTo(screenScale(44));
    }];
    
    UIView *wayThread = [[UIView alloc]init];
    wayThread.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:wayThread];
    [wayThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(threadView).with.offset(screenScale(44));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    ///截止日期
    
    UILabel *dateLabel = [[UILabel alloc]init];
    dateLabel.text = @"众筹天数";
    dateLabel.numberOfLines = 1;
    dateLabel.textColor = getColor(@"4a4a4a");
    dateLabel.textAlignment = NSTextAlignmentLeft;
    dateLabel.font = get4sFont(12);
    [self addSubview:dateLabel];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        
        
    }];
    
    _dateTextField = [[UITextField alloc]init];
    _dateTextField.textColor = getColor(@"4a4a4a");
    _dateTextField.placeholder = @"请填写众筹天数";
    _dateTextField.keyboardType = UIKeyboardTypeNumberPad;
    _dateTextField.font = get4sFont(12);
    _dateTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:_dateTextField];
    [_dateTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(2));
        make.left.mas_equalTo(self).with.offset(screenScale(85));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        make.height.mas_equalTo(screenScale(44));
    }];
    
    UIView *dateThread = [[UIView alloc]init];
    dateThread.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:dateThread];
    [dateThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(44));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    /// 项目定位
    
    UILabel *locationLabel = [[UILabel alloc]init];
    locationLabel.text = @"项目定位";
    locationLabel.numberOfLines = 1;
    locationLabel.textColor = getColor(@"4a4a4a");
    locationLabel.textAlignment = NSTextAlignmentLeft;
    locationLabel.font = get4sFont(12);
    [self addSubview:locationLabel];
    [locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(dateThread).with.offset(screenScale(15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        
        
    }];
    
    _locationLabel = [[UILabel alloc]init];
    _locationLabel.text = @"位置";
    _locationLabel.numberOfLines = 1;
    _locationLabel.textColor = getColor(@"4a4a4a");
    _locationLabel.textAlignment = NSTextAlignmentLeft;
    _locationLabel.font = get4sFont(12);
    [self addSubview:_locationLabel];
    [_locationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(dateThread).with.offset(screenScale(2));
        make.left.mas_equalTo(self).with.offset(screenScale(85));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        make.height.mas_equalTo(screenScale(44));
    }];
    
    UIView *locationThread = [[UIView alloc]init];
    locationThread.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:locationThread];
    [locationThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(dateThread).with.offset(screenScale(44));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    UIButton *locationBtn = [ConfigXp buttonWithFrame:CGRectZero
                                                title:nil
                                           titleColor:nil
                                                 font:nil
                                      backgroundColor:nil
                                                image:nil];
    [locationBtn addTarget:self action:@selector(locationbtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:locationBtn];
    [locationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(dateThread).with.offset(0);
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(scrWidth());
        make.height.mas_equalTo(screenScale(44));
    }];
    
    /// 学校名称
    
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.text = @"学校名称";
    nameLabel.numberOfLines = 1;
    nameLabel.textColor = getColor(@"4a4a4a");
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = get4sFont(12);
    [self addSubview:nameLabel];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(locationThread).with.offset(screenScale(15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        
        
    }];
    
    _nameTextField = [[UITextField alloc]init];
    _nameTextField.textColor = getColor(@"4a4a4a");
    _nameTextField.placeholder = @"请输入完整的学校名称";
    _nameTextField.font = get4sFont(12);
    _nameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:_nameTextField];
    [_nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(locationThread).with.offset(screenScale(2));
        make.left.mas_equalTo(self).with.offset(screenScale(85));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        make.height.mas_equalTo(screenScale(44));
    }];
    
    UIView *nameThread = [[UIView alloc]init];
    nameThread.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:nameThread];
    [nameThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(locationThread).with.offset(screenScale(44));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    /*
    _dateLabel = [[UILabel alloc]init];
    _dateLabel.textColor = getColor(@"4a4a4a");
    _dateLabel.text = @"2017-07-17 10:38";
    _dateLabel.font = get4sFont(11);
    [self addSubview:_dateLabel];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(17));
        make.left.mas_equalTo(self).with.offset(screenScale(85));
        
    }];
    
    _dayLabel = [[UILabel alloc]init];
    _dayLabel.textColor = getColor(@"4a4a4a");
    _dayLabel.text = @"共15天";
    _dayLabel.font = get4sFont(12);
    [self addSubview:_dayLabel];
    [_dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(15));
        make.left.mas_equalTo(_dateLabel.mas_right).with.offset(screenScale(10));
        
    }];
    
    UILabel *minDayLabel = [[UILabel alloc]init];
    minDayLabel.textColor = getColor(@"9b9b9b");
    minDayLabel.text = @"3天";
    minDayLabel.font = get4sFont(12);
    [self addSubview:minDayLabel];
    [minDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(47.5));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        
        
    }];
    
    UISlider *slider = [[UISlider alloc]init];
    slider.minimumTrackTintColor = getColor(@"5eca34");
    slider.minimumValue = 3;
    slider.maximumValue = 30;
    slider.value = (slider.minimumValue + slider.maximumValue) / 2;// 设置初始值
    slider.continuous = YES;// 设置可连续变化
    [slider setThumbImage:[UIImage imageNamed:@"button_icon"] forState:UIControlStateNormal];
    [slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];// 针对值变化添加响应方法
    [self addSubview:slider];
    [slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(51.5));
        make.left.mas_equalTo(self).with.offset(screenScale(46));
        make.width.mas_equalTo( screenScale(275));
        make.height.mas_equalTo(screenScale(6));
    }];
    
    UILabel *maxDayLabel = [[UILabel alloc]init];
    maxDayLabel.textColor = getColor(@"9b9b9b");
    maxDayLabel.text = @"30天";
    maxDayLabel.font = get4sFont(12);
    [self addSubview:maxDayLabel];
    [maxDayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(47.5));
        make.left.mas_equalTo(self).with.offset(screenScale(331));
        
        
    }];
    
    UIView *dateThread = [[UIView alloc]init];
    dateThread.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:dateThread];
    [dateThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(wayThread).with.offset(screenScale(82.5));
        make.left.mas_equalTo(self).with.offset(0);
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(8));
    }];
    */
    
    /// 筹款标题 描述
    
    _titleTextField = [[UITextField alloc]init];
    _titleTextField.textColor = getColor(@"4a4a4a");
    _titleTextField.placeholder = @"筹款标题";
    _titleTextField.font = get4sFont(12);
    _titleTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self addSubview:_titleTextField];
    [_titleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameThread.mas_bottom).with.offset(screenScale(2));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        make.height.mas_equalTo(screenScale(44));
    }];
    
    UIView *titleThread = [[UIView alloc]init];
    titleThread.backgroundColor = getColor(@"f5f5f5");
    [self addSubview:titleThread];
    [titleThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameThread.mas_bottom).with.offset(screenScale(44));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(15));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    _messageTextView = [[UITextView alloc]init];
    _messageTextView.font = get4sFont(12);
    _messageTextView.backgroundColor = getColor(@"ffffff");
    _messageTextView.textColor = getColor(@"4a4a4a");
    [self addSubview:_messageTextView];
    [_messageTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleThread).with.offset(screenScale(9));
        make.left.mas_equalTo(self).with.offset(screenScale(9));
        make.right.mas_equalTo(self).with.offset(screenScale(-10));
        make.height.mas_equalTo(screenScale(108));
    }];
    
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"建议向西描述帮助情况：如申请扶贫助学团体或个人的经济状况／资金用途及未来筹划等";
    placeHolderLabel.numberOfLines = 0;
    placeHolderLabel.font = get4sFont(12);
    
    placeHolderLabel.textColor = getColor(@"d9d9d9");
    [placeHolderLabel sizeToFit];
    [_messageTextView addSubview:placeHolderLabel];
    [_messageTextView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    
    UIView *messageThread = [[UIView alloc]init];
    messageThread.backgroundColor = getColor(@"eeeeee");
    [self addSubview:messageThread];
    [messageThread mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_messageTextView.mas_bottom).with.offset(screenScale(1));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.width.mas_equalTo(scrWidth() - screenScale(30));
        make.height.mas_equalTo(screenScale(0.5));
    }];
    
    ///
    
    UILabel *bottomLabel = [[UILabel alloc]init];
    bottomLabel.textColor = getColor(@"d9d9d9");
    bottomLabel.numberOfLines = 2;
    bottomLabel.text = @"建议上传家庭经济情况、财产证明和贫穷状况等拍照，提高项目可信度";
    bottomLabel.font = get4sFont(11);
    [self addSubview:bottomLabel];
    [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self).with.offset(screenScale(-15));
        make.left.mas_equalTo(self).with.offset(screenScale(15));
        make.right.mas_equalTo(self).with.offset(screenScale(-15));
        
    }];
    
}

// slider变动时改变label值
- (void)sliderValueChanged:(id)sender {
    
    UISlider *slider = (UISlider *)sender;
    NSLog(@"%.0f",slider.value);
}

- (void)locationbtnClick{

    [self endEditing:YES];
    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    _bgView.alpha = 0.6;
    [UIView commitAnimations];
    _bgView.hidden = NO;

    [[[UIApplication sharedApplication]keyWindow] addSubview:self.pickerView];
    
    [_pickerView show];
    
}
- (AddressPickerView *)pickerView{
    if (!_pickerView) {
        
        _pickerView = [[AddressPickerView alloc]initWithFrame:CGRectMake(0, scrHeight() , scrWidth(), screenScale(415))];
        _pickerView.delegate = self;
        _pickerView.mark = @"2";
    }
    return _pickerView;
}

#pragma mark - AddressPickerViewDelegate

- (void)cancelBtnClick{
    
    [UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    _bgView.alpha = 0.1;
    [UIView commitAnimations];
    _bgView.hidden = YES;
    [self.pickerView hide];
    
}

- (void)sureBtnClickReturnProvince:(NSString *)province City:(NSString *)city Area:(NSString *)area{
    
//    [messageArray replaceObjectAtIndex:3 withObject:[NSString stringWithFormat:@"%@ %@ %@",province,city,area]];
    //    [_personTableView reloadData];
    [self cancelBtnClick];
    NSLog(@"%@",[NSString stringWithFormat:@"%@ %@ %@",province,city,area]);
    _locationLabel.text = [NSString stringWithFormat:@"%@ %@ %@",province,city,area];
    
}

@end
